var roleTypeNum = $("#roleTypeNum").val(); 
var msgg = $("#msgg").val();
var code = $("#code").val();
$(function(){
	if( code== 1) {
		layer.msg(msgg);
	}
})
//操作按钮
function buttonFormatter(value, row,index) {
	if(row.rowId == 1){
		return ;
	}
	var f = "";
	if(parseInt(roleTypeNum) < parseInt(row.roleType)){
		f = "<button id='btn_edit' type='button' onclick='showMenuRole("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>权限配置</button>";  
	}
 	var e = "<button id='btn_edit' type='button' onclick='addRole("+row.rowId+");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>修改</button>";  
 	var d = "<button id='btn_edit' type='button' onclick='deleteRole("+row.rowId+",\""+row.roleName+"\");'  class='btn btn-default btn-sm'><span class='glyphicon glyphicon-remove'></span>删除</button>";  
  	return f+'&nbsp;'+e+'&nbsp;'+d;
}
function typeFormatter(value, row) {
	//1 超级管理员 2总经理 3 部门经理 4 主管  5 客服    
	var roleTypeList = $("#roleTypeList").val();
	roleTypeList = eval(roleTypeList);
	for(var roleType in roleTypeList){
		if(row.roleType == roleTypeList[roleType].value){
			if (row.roleType == 1) {
				return '<span class="text-success">超级管理员 </span>';
			} else {
				return '<span class="text-warning">' + roleTypeList[roleType].label + '</span>';
			}
		}
	}
}
//删除
function deleteRole(rowId, roleName){
	layer.confirm('您确认删除角色<a style="color:red">'+'"'+roleName+'"'+'</a>吗？', {
  	btn: ['确认', '取消'] //可以无限个按钮
	}, 
	function(){
		if (rowId == null || rowId == '') {
			layer.msg("删除失败,id不能为空!");
			return;
		}
		$.post(JSSYSMANAGERV1 + "/role/roleDelete?rowId="+rowId,function(result){
			//正数为正确的提示   负数 为错误
 			var err = {'0':'删除成功','-1':'删除失败'};
			if (result != null  && result != '') {
  		  		layer.msg(err[result]);
  		  		roleFind();
  			}
	  	});
	}, function(){
		return;
	});
}
  
  
//添加/修改
function addRole(id){
  	layer.open({
	  	type: 2,
	  	title: "添加角色",
	  	closeBtn: 1,
	  	shadeClose: true,
	  	area: ['500px', '300px'],
	  	content: JSSYSMANAGERV1 + '/role/roleEditer?rowId=' + id,
	 	btn: ["确 认","关 闭"],
	  	yes: function(index, layero){
	    	var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
			iframeWin.add();
	  	}
	});
}

$(function(){
  	$("#roleTable").bootstrapTable({ 
		url: JSSYSMANAGERV1 + "/role/role.json",
		method:"get", 
		pagination:true,
		sidePagination:"server",
		queryParams: function(params) {
  			return $.extend({}, params, parseJson(decodeURIComponent($("#roleForm").serialize())));     
 		}
 	}); 
})
function roleFind(){
  	$("#roleTable").bootstrapTable("refresh",{} ); 
}
  
function showMenuRole(id){
 	layer.open({
		type: 2,
	  	title: "权限配置",
	  	closeBtn: 1,
	  	shadeClose: true,
	  	area: ['300px', '550px'],
	  	content: JSSYSMANAGERV1 + '/role/showMenuRole?id='+id,
	  	btn: ["确 认","关 闭"],
	  	yes: function(index, layero){
        	var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
	        iframeWin.submit();
	  	}
	});
}